package Collection;

import java.util.*;

public class Exercise02 {
    public static void main(String[] args) {
        List<Integer>list=new ArrayList<>();
        for (int i=0;i<10;i++){
            list.add(i*10);
        }
        System.out.println("list:"+list);

        List<Integer>subList= list.subList(2,5);
        System.out.println("subList:"+subList);

        for (int i=0;i<subList.size();i++){
            subList.set(i,subList.get(i)*10);
        }
        System.out.println("subList:"+subList);
        System.out.println("list"+list);
        list.set(5,999);
        System.out.println("list:"+list);
        System.out.println("subList"+subList);


        List<Integer>list1 =new ArrayList<>();
        for (int i=0;i<10;i++){
            list1.add(i*10);
        }
        System.out.println("list1:"+list1);

        List<Integer>subList1=list1.subList(0,5);
        System.out.println("subList1"+subList1);
        for (int i=0;i<subList1.size();i++){
            subList1.set(i,subList1.get(i)*10);
        }

        System.out.println("subList1:"+subList1);
        System.out.println("list1"+list1);

        list1.set(2,77);
        System.out.println("list1:"+list1);
        System.out.println("subList1"+subList1);

        list1.remove(1);
        System.out.println("list1"+list1);
        System.out.println("s");

        /*
        List<String>list=new ArrayList<>();
        list.add("qwq");
        list.add("qwe");
        list.add("OvO");
        System.out.println("list原始数据排序："+list);

        Collections.sort(list, new Comparator<String>() {
            public int compare(String o1, String o2) {
                return o1.length()-o2.length();
            }
        });

        Collections.sort(list,(o1, o2) -> o1.length()-o2.length());
        System.out.println("list排序后的数据："+list);

        List<String>list1=new ArrayList<>();
        list.add("tom");
        list.add("jerry");
        list.add("bob");
        list.add("rose");
        list.add("kobe");
        list.add("black");
        System.out.println("lis原始数据："+list);

        Collections.sort(list);
        System.out.println("list排序后数据："+list);


        List<String>list2=new ArrayList<>();
        list2.add("OVO");
        list2.add("MOM");
        list2.add("WOW");
        System.out.println("list原始数据："+list2);

        Collections.sort(list2, new Comparator<String>() {
            public int compare(String o1, String o2) {
                return o1.length()-o2.length();
            }
        });
        Collections.sort(list2,(o1, o2) -> o1.length()-o2.length());
        System.out.println("list2排序后的数据："+list2);

        List<String>list3=new ArrayList<>();
        list3.add("tom");
        list3.add("jerry");
        list3.add("black");
        list3.add("bob");
        System.out.println("list3原始数据："+list3);

        Collections.sort(list3);
        System.out.println("list3排列后数据："+list3);




        List<Point>list=new ArrayList<>();
        list.add(new Point(5,8));
        list.add(new Point(7,6));
        list.add(new Point(75,69));
        list.add(new Point(12,3));
        list.add(new Point(77,49));
        list.add(new Point(22,55));
        System.out.println("list原始数据："+list);

        list.sort(new Comparator <Point>() {
            public int compare(Point o1,Point o2) {
                return o1.getX()-o2.getX();
            }
        });
        System.out.println("list排序后数据："+list);

        list.sort((o1, o2) -> {
            int len1= o1.getX()* o1.getX()+ o1.getY()* o1.getY();
            int len2= o2.getX()* o2.getX()+ o2.getY()* o2.getY();
            return len1-len2;
        });

        Collections.sort(list, new Comparator<Point>() {
            public int compare(Point o1,Point o2) {
                int len1=o1.getX()*o1.getX()+ o1.getY()*o1.getY();
                int len2=o2.getX()* o2.getX()+o2.getY()*o2.getY();
                return len1-len2;
            }
        });
        System.out.println("list排列后数据："+list);






        Random rand=new Random();
        List<Integer>list=new ArrayList<>();
        for (int i=0;i<10;i++){
            list.add(rand.nextInt(100));
        }
        System.out.println("list原始数据："+list);

        Collections.sort(list);
        System.out.println("list排序后数据："+list);
        System.out.println("第1个元素为："+ list.get(0));

        Collections.reverse(list);
        System.out.println("list反转后数据："+list);
        System.out.println("第1个元素为："+ list.get(0));

        Random rand1=new Random();
        List<Integer>list1=new ArrayList<>();
        for (int i=0;i<10;i++){
            list1.add(rand1.nextInt(1000));
        }
        System.out.println("list初始数据："+list1);

        Collections.sort(list1);
        System.out.println("list排序后数据："+list1);

        Collections.reverse(list1);
        System.out.println("list反转后数据："+list1);
        System.out.println("第1个元素："+ list1.get(0));






        List<String>list =new ArrayList<>();
        list.add("one");
        list.add("twe");
        list.add("three");
        list.add("four");
        list.add("five");
        list.add("two");
        System.out.println("list:"+list);

        Set<String>set=new HashSet<>();
        set.addAll(list);
        System.out.println("set:"+set);

        List<String>list1=new ArrayList<>();
        list.add("one");
        list.add("two");
        list.add("three");
        list.add("four");
        list.add("five");
        list.add("two");
        Set<String>set1=new HashSet<>();
        set.addAll(list);
        System.out.println("set1："+set1);



        List<String>list=new LinkedList<>();
        list.add("qwq");
        list.add("wow");
        list.add("mom");
        list.add("WoW");
        list.add("mVm");
        list.add("qoq");
        list.add("qvq");
        System.out.println("list:"+list);

        String e=list.get(2);
        System.out.println(e);
        for (int i=0;i<list.size();i++){
            System.out.println(list.get(i));
        }
        Iterator<String>it= list.iterator();
        while (it.hasNext()){
            System.out.println(it.next());
        }
        for (String s:list){
                System.out.println(s);
            }


        String old= list.set(2,"six");
        System.out.println("list:"+list);
        System.out.println(old);

        String s= list.remove(2);
        System.out.println("list:"+list);
        System.out.println(s);

        list.add(3,"seven");
        System.out.println(list);


        list.add("one");
        list.add("two");
        list.add("three");
        list.add("four");
        list.add("five");
        list.add("six");
        list.add("seven");
        System.out.println("list:"+list);

        String e=list.get(2);
        System.out.println(e);
        for (int i=0;i<list.size();i++){
            System.out.println(list.get(i));
        }
        Iterator<String>it= list.iterator();
        while (it.hasNext()){
            System.out.println(it.next());
        }
        for (String s:list){
            System.out.println(s);
        }


        String old= list.set(5,"nine");
        System.out.println("list:"+list);
        System.out.println(old);

        String s= list.remove(2);
        System.out.println("list:"+list);
        System.out.println(s);

        list.add(3,"seven");
        System.out.println(list);*/



/*
        Collections.sort(list, new Comparator<String>() {
            public int compare(String o1, String o2) {
                return o1.length()-o2.length();
            }
        });

        Collections.sort(list,(String o1, String o2)->{
                return o1.length()-o2.length();
        });

        Collections.sort(list,(o1, o2) -> {
            return o1.length()-o2.length();
        });

        Collections.sort(list,(o1, o2) -> o1.length()-o2.length());

        List<String>list1=new ArrayList<>();

        Collections.sort(list, new Comparator<String>() {
            @Override
            public int compare(String o1, String o2) {
                return o1.length()-o2.length();
            }
        });

        Collections.sort(list,(String o1, String o2)->{
                return o1.length()-o2.length();
        });

        Collections.sort(list,(o1, o2) -> {
            return o1.length()-o2.length();
        });

        Collections.sort(list,(o1, o2) -> o1.length()-o2.length());
 */
    }
}
